package com.eleadmin.common.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eleadmin.common.goods.domain.pojo.Goods;
import com.eleadmin.common.goods.domain.req.GoodsReq;
import com.eleadmin.common.goods.mapper.GoodsMapper;
import com.eleadmin.common.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @ClassName GoodsServiceImpl
 * @Description 描述
 * @Author ShiYu.Cui
 * @Date 2024/4/20 12:53
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper,Goods> implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;
    @Override
    public List<Goods> goodsList(GoodsReq goodsReq) {
        LambdaQueryWrapper<Goods> queryWrapper = new LambdaQueryWrapper<>();


        // 如果 goodsReq 的 title 不为空，则按 title 模糊查询
        if (goodsReq.getTitle() != null) {
            queryWrapper.like(Goods::getTitle, goodsReq.getTitle());
        }

        // 如果 goodsReq 的 goodId 不为空，则按 goodId 模糊查询
        if (goodsReq.getGoodId() != null) {
            queryWrapper.like(Goods::getGoodId, goodsReq.getGoodId());
        }
        List<Goods> goodsList = goodsMapper.selectList(queryWrapper);
        return goodsList;
    }
}
